
local function MakeProjectile(prefab,bank,build,defaultanim,ground,speed,rad,assets,masterfn,commonfn)
    ------------------------- prefab名，bank，build，anim名，贴地，速度，半径，资源，调整函数
local function fn()
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()
    local net = inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)
    RemovePhysicsColliders(inst)
    
    anim:SetBank(bank)
    anim:SetBuild(build)
    anim:PlayAnimation(defaultanim,true)
    if ground then
        anim:SetOrientation(ANIM_ORIENTATION.OnGround)
    end
    
    inst:AddTag("projectile")
    inst.persists = false
    
    if commonfn then
        commonfn(inst)
    end

    inst.entity:SetPristine()
    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("projectile")
    inst.components.projectile:SetSpeed(speed or 30)
    inst.components.projectile:SetHoming(false)
    inst.components.projectile:SetHitDist(rad or 1)
    inst.components.projectile:SetOnHitFn(inst.Remove)
    inst.components.projectile:SetOnMissFn(inst.Remove)
 
    if masterfn then
        masterfn(inst)
    end

    return inst
end

    return Prefab( "common/projectile/"..prefab, fn, assets) 
end

local function CalcDeltaAngle(angle1,angle2,abs)
    local delta = math.mod(angle2 - angle1,360)  --   -360~360
    delta = delta < 0 and delta+360 or delta     --    0 ~ 360
    if abs then
        return delta>180 and 360-delta or delta  --  0~180
    else
        return delta 
    end
end

PUELLA_MOD_FN = {
    MakeProjectile = MakeProjectile,
    DeltaAngle = CalcDeltaAngle,
}

GLOBAL.PUELLA_MOD_FN = PUELLA_MOD_FN
